<?php

class Core_Backend_Component_Foundation_View_Catalogue_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar){
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('foundation/catalogue/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form){
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
             ->setId('catalogue_form')
             ->addHiddenField('id', 'catalogue[id]');
        $form->addTextboxField($this->__('share.label.code'), 'code', 'catalogue[code]', TRUE)
                ->addRequiredRule();        
        $form->addTextboxField($this->__('share.label.name'), 'name', 'catalogue[name]', TRUE)
                ->addRequiredRule();
//        $form->addTextboxField($this->__('share.label.sef_url'), 'sef_url', 'catalogue_[sef_url]');
//        $form->addSelectField($this->__('share.label.template'), 'template_id', "category[template_id]")
//             	->bindData($this->getTemplates(), 'name', 'id')->setOption('--', 0);
        $parents = $this->getParents()->toArray();
        $form->addComboTreeField($this->__('foundation.label.parent_catalogue'), 'parent_codes', "catalogue[parent_codes][]")
             ->bindData($parents, 0, array('valueKey'=>'code', 'textKey'=>'name', 'parentKey'=>'parent_code', 'childKey'=>'code'))
             ->setSize(10)
             ->setMultiple(TRUE);
        if(!is_null($entity)){
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }
}